unit Class_Mast_IN_PRMS;

interface
uses
  Classes,SysUtils,DB,Uni,UniEngine;

type
  TMAST=class(TUniEngine)
  private
    FMASTIDEX : Integer;
    FMASTCODE : string;
    FMASTNAME : string;
    FMASTPSWD : string;              
    FMASTMEMO : string;
    FORDRIDEX : Integer;
    FISROLXED : Integer;
    FMASTLEVL : Integer;
    FMASTGOAL : string;
    FLICNBIMS : string;
  protected
    procedure SetParameters;override;
    function  GetStrInsert:string;override;
    function  GetStrUpdate:string;override;
    function  GetStrDelete:string;override;
  public
    function  GetStrsIndex:string;override;
  public
    function  GetNextIdex:Integer;overload;
    function  GetNextIdex(AUniConnection:TUniConnection):Integer;overload;
  public
    function  CheckExist(AUniConnection:TUniConnection):Boolean;override;
  public
    destructor  Destroy; override;
    constructor Create;  
  published
    property MASTIDEX : Integer read FMASTIDEX  write FMASTIDEX;
    property MASTCODE : string read FMASTCODE  write FMASTCODE;
    property MASTNAME : string read FMASTNAME  write FMASTNAME;
    property MASTPSWD : string read FMASTPSWD  write FMASTPSWD;
    property MASTMEMO : string read FMASTMEMO  write FMASTMEMO;
    property ORDRIDEX : Integer read FORDRIDEX  write FORDRIDEX;
    property ISROLXED : Integer read FISROLXED  write FISROLXED;
    property MASTLEVL : Integer read FMASTLEVL  write FMASTLEVL;
    property MASTGOAL : string read FMASTGOAL  write FMASTGOAL;
    property LICNBIMS : string read FLICNBIMS  write FLICNBIMS;    
  public
    class function  ReadDS(AUniQuery:TUniQuery):TUniEngine;override;
    class procedure ReadDS(AUniQuery:TUniQuery;var Result:TUniEngine);override;
    class function  CopyIt(AMAST:TMAST):TMAST;overload;        
    class procedure CopyIt(AMAST:TMAST;var Result:TMAST);overload;

    class function  SignDB(AMastCode,AMastPswd:string;AUniConnection:TUniConnection;ASignAddr:string=''):Integer;        
  end;

implementation

{ TMAST }
procedure TMAST.SetParameters;
begin
  inherited;
  with FUniSQL.Params do
  begin
    case FOptTyp of
      otAddx:
      begin
        ParamByName('MAST_IDEX').Value := MASTIDEX;
        ParamByName('MAST_CODE').Value := MASTCODE;
        ParamByName('MAST_NAME').Value := MASTNAME;
        ParamByName('MAST_PSWD').Value := MASTPSWD;
        ParamByName('MAST_MEMO').Value := MASTMEMO;
        ParamByName('ORDR_IDEX').Value := ORDRIDEX;
        ParamByName('IS_ROLXED').Value := ISROLXED;
        ParamByName('MAST_LEVL').Value := MASTLEVL;
        ParamByName('MAST_GOAL').Value := MASTGOAL;
        ParamByName('LICN_BIMS').Value := LICNBIMS; 
      end;
      otEdit:
      begin
        ParamByName('MAST_IDEX').Value := MASTIDEX;
        ParamByName('MAST_CODE').Value := MASTCODE;
        ParamByName('MAST_NAME').Value := MASTNAME;
        ParamByName('MAST_PSWD').Value := MASTPSWD;
        ParamByName('MAST_MEMO').Value := MASTMEMO;
        ParamByName('ORDR_IDEX').Value := ORDRIDEX;
        ParamByName('IS_ROLXED').Value := ISROLXED;
        ParamByName('MAST_LEVL').Value := MASTLEVL;
        ParamByName('MAST_GOAL').Value := MASTGOAL;
        ParamByName('LICN_BIMS').Value := LICNBIMS; 
      end;  
      otDelt:
      begin
        ParamByName('MAST_IDEX').Value := MASTIDEX;
        ParamByName('MAST_CODE').Value := MASTCODE;
 
      end;  
    end;
  end;
end;

function TMAST.CheckExist(AUniConnection: TUniConnection): Boolean;
begin
  Result:=CheckExist('TBL_MAST',['MAST_IDEX',MASTIDEX,'MAST_CODE',MASTCODE],AUniConnection);
end;

function TMAST.GetNextIdex: Integer;
begin

end;

function TMAST.GetNextIdex(AUniConnection: TUniConnection): Integer;
begin

end;

function TMAST.GetStrDelete: string;
begin
  Result:='DELETE FROM TBL_MAST WHERE   MAST_IDEX=:MAST_IDEX AND MAST_CODE=:MAST_CODE';
end;

function TMAST.GetStrInsert: string;
begin
  Result:='INSERT INTO TBL_MAST'
         +'    ( MAST_IDEX, MAST_CODE, MAST_NAME, MAST_PSWD, MAST_MEMO'
         +'    , ORDR_IDEX, IS_ROLXED, MAST_LEVL, MAST_GOAL, LICN_BIMS)'
         +'    VALUES'
         +'    (:MAST_IDEX,:MAST_CODE,:MAST_NAME,:MAST_PSWD,:MAST_MEMO'
         +'    ,:ORDR_IDEX,:IS_ROLXED,:MAST_LEVL,:MAST_GOAL,:LICN_BIMS)';
end;

function TMAST.GetStrsIndex: string;
begin
  Result:=Format('%D-%S',[MASTIDEX,MASTCODE]);
end;

function TMAST.GetStrUpdate: string;
begin
  Result:='UPDATE  TBL_MAST SET'
         +'    MAST_NAME=:MAST_NAME,'
         +'    MAST_PSWD=:MAST_PSWD,'
         +'    MAST_MEMO=:MAST_MEMO,'
         +'    ORDR_IDEX=:ORDR_IDEX,'
         +'    IS_ROLXED=:IS_ROLXED,'
         +'    MAST_LEVL=:MAST_LEVL,'
         +'    MAST_GOAL=:MAST_GOAL,'
         +'    LICN_BIMS=:LICN_BIMS'
         +'    WHERE MAST_IDEX=:MAST_IDEX'
         +'    AND   MAST_CODE=:MAST_CODE';
end;

constructor TMAST.Create;
begin

end;

destructor TMAST.Destroy;
begin

  inherited;
end;

class function TMAST.ReadDS(AUniQuery: TUniQuery): TUniEngine;
var
  I:Integer;
  Field:TField;
begin
  Result:=TMAST.Create;

  with TMAST(Result) do
  begin
    for I:=0 to AUniQuery.Fields.Count-1 do
    begin
      Field:=AUniQuery.Fields.Fields[I];
      if Field.FieldName='MAST_IDEX' then
      begin
        MASTIDEX :=Field.AsInteger;
      end else
      if Field.FieldName='MAST_CODE' then
      begin
        MASTCODE :=Field.AsString;
      end else
      if Field.FieldName='MAST_NAME' then
      begin
        MASTNAME :=Field.AsString;
      end else
      if Field.FieldName='MAST_PSWD' then
      begin
        MASTPSWD :=Field.AsString;
      end else
      if Field.FieldName='MAST_MEMO' then
      begin
        MASTMEMO :=Field.AsString;
      end else
      if Field.FieldName='ORDR_IDEX' then
      begin
        ORDRIDEX :=Field.AsInteger;
      end else
      if Field.FieldName='IS_ROLXED' then
      begin
        ISROLXED :=Field.AsInteger;
      end else
      if Field.FieldName='MAST_LEVL' then
      begin
        MASTLEVL :=Field.AsInteger;
      end else
      if Field.FieldName='MAST_GOAL' then
      begin
        MASTGOAL :=Field.AsString;
      end else
      if Field.FieldName='LICN_BIMS' then
      begin
        LICNBIMS :=Field.AsString;
      end;
    end
  end;  
end;

class procedure TMAST.ReadDS(AUniQuery: TUniQuery; var Result: TUniEngine);
var
  I:Integer;
  Field:TField;
begin
  if Result=nil then Exit;

  with TMAST(Result) do
  begin
    for I:=0 to AUniQuery.Fields.Count-1 do
    begin
      Field:=AUniQuery.Fields.Fields[I];
      if Field.FieldName='MAST_IDEX' then
      begin
        MASTIDEX :=Field.AsInteger;
      end else
      if Field.FieldName='MAST_CODE' then
      begin
        MASTCODE :=Field.AsString;
      end else
      if Field.FieldName='MAST_NAME' then
      begin
        MASTNAME :=Field.AsString;
      end else
      if Field.FieldName='MAST_PSWD' then
      begin
        MASTPSWD :=Field.AsString;
      end else
      if Field.FieldName='MAST_MEMO' then
      begin
        MASTMEMO :=Field.AsString;
      end else
      if Field.FieldName='ORDR_IDEX' then
      begin
        ORDRIDEX :=Field.AsInteger;
      end else
      if Field.FieldName='IS_ROLXED' then
      begin
        ISROLXED :=Field.AsInteger;
      end else
      if Field.FieldName='MAST_LEVL' then
      begin
        MASTLEVL :=Field.AsInteger;
      end else
      if Field.FieldName='MAST_GOAL' then
      begin
        MASTGOAL :=Field.AsString;
      end else
      if Field.FieldName='LICN_BIMS' then
      begin
        LICNBIMS :=Field.AsString;
      end;
    end
  end;  
end;

class function  TMAST.CopyIt(AMAST: TMAST): TMAST;
begin
  Result:=TMAST.Create;
  TMAST.CopyIt(AMAST,Result)
end;

class procedure TMAST.CopyIt(AMAST:TMAST;var Result:TMAST);
begin
  if Result=nil then Exit;
  Result.MASTIDEX :=AMAST.MASTIDEX;
  Result.MASTCODE :=AMAST.MASTCODE;
  Result.MASTNAME :=AMAST.MASTNAME;
  Result.MASTPSWD :=AMAST.MASTPSWD;
  Result.MASTMEMO :=AMAST.MASTMEMO;
  Result.ORDRIDEX :=AMAST.ORDRIDEX;
  Result.ISROLXED :=AMAST.ISROLXED;
  Result.MASTLEVL :=AMAST.MASTLEVL;
  Result.MASTGOAL :=AMAST.MASTGOAL;
  Result.LICNBIMS :=AMAST.LICNBIMS;
end;

class function TMAST.SignDB(AMastCode, AMastPswd: string;
  AUniConnection: TUniConnection; ASignAddr: string): Integer;
var
  SQLA:string;
  MastA:TMast;
begin
  SQLA:='SELECT * FROM TBL_MAST WHERE MAST_CODE=%S AND MAST_PSWD=%S';
  SQLA:=Format(SQLA,[QuotedStr(AMastCode),QuotedStr(AMastPswd)]);

  MastA:=TMast(TMast.ReadDB(SQLA,AUniConnection));
  if MastA<>nil then
  begin
    FreeAndNil(MastA);
    Result:=1;
  end;  
end;

end.

